﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace QuanLyCuaHangBanMayTinh
{
    class NhapHangDAO
    {
        static public DataTable SelectmhAll()
        {
            string sql = "select * from MATHANG";
            DataTable dt = DataAccess.ExecQuery(sql);
            return dt;
        }
        static public void Insert(NhapHangDTO mh)
        {
            string sql = "insert into MATHANG(TenMatHang,NhanVienNhap,NgayLapPhieu,DonViTinh,SoLuong,DonGia,TenDaiLy) values('" + mh.TenMatHang + "','" + mh.NhanVienNhap + "','" + mh.NgayLapPhieu + "','" + mh.DonViTinh + "','" + mh.SoLuong + "','" + mh.DonGia + "','" + mh.TenDaiLy + "')";
            DataAccess.ExecNonQuery(sql);
        }
        
        static public void Update(NhapHangDTO mh)
        {
            string sql = "update MATHANG set TenMatHang = '" + mh.TenMatHang + "' where MaMatHang = '" + mh.MaMatHang;
            DataAccess.ExecNonQuery(sql);
        }
 
        
        static public void Delete(NhapHangDTO mh)
        {
            string sql = "delete from MATHANG where MaMatHang = " + mh.MaMatHang;
            DataAccess.ExecNonQuery(sql);
        }
        
        static public NhapHangDTO SelectmhByName(string name)
        {
            string sql = "select * from MATHANG where TenMatHang = '" + name + "'";
            DataTable dt = DataAccess.ExecQuery(sql);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                NhapHangDTO mh = new NhapHangDTO();
                mh.TenMatHang = dt.Rows[0].ItemArray[1].ToString();
                return mh;
            }
        }
    }
}
